﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace VideoReflector.Converters
{
    /// <summary>
    /// Multi Value Converter which takes one or more numeric (double) values as input, finds their product, takes
    /// the integer part, creates a new TimeSpan with that number of seconds and returns the string representation of
    /// the TimeSpan object
    /// </summary>
    [ValueConversion(typeof(Double), typeof(string))]
    public class TimeSpanSecondsMultiplierConverter : ConverterWithMarkupExtension, IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double result = 1.0;
            foreach(var value in values)
            {
                var dblValue = System.Convert.ToDouble(value);
                result *= dblValue;
            }
            var timeSpan = new TimeSpan(0, 0, System.Convert.ToInt32(result));
            return timeSpan.ToString();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
